<template>
	<view>
		<view class="box">
			<view class="addres" v-for="address in addressList" :key="address.id" @click="toAddAress(address.id,address)">
				<view class="addresCont">
					<view class="addresIcon">
						<image class="contIcon" src="../../static/images/work/address.png"></image>
					</view>
					<view class="contInfoBox">
						<view class="infoTop">
							<text>{{ address.name }}</text><text style="margin-left: 20rpx;">{{ address.mobile }}</text>
						</view>
						<view class="infoBom">
							地址:{{ address.detailAddress }}
						</view>
					</view>
					<image class="contIcon2" src="../../static/images/minde/arrow.png"></image>
				</view>
			</view>
		</view>
		<view class="but" @click="toAddAress()">
			添加收货地址
		</view>
	</view>
</template>

<script>
	import {
		pageList
	} from '@/api/address'
	export default {
		data() {
			return {
				checked:false,//是否是选择地址
				addressList:[],
			}
		},
		onShow() {
			this.getList();
		},
		onLoad(e) {
			if(e.type==1){
				this.checked = true
			}
		},
		methods: {
			//添加收货地址
			toAddAress(id,item) {
				if(this.checked&&item){
					console.log(item)
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2];
					prevPage.$vm.address = item;
					uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
						delta: 1
					});
				}else{
					let params = '';
					if (id) {
						params = '?id=' + id
					}
					this.$tab.navigateTo('/pagesA/addAress/addAress' + params)
				}
			},
			getList() {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				pageList().then(res => {
					that.addressList = res.data;
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}

	.box {
		width: 690rpx;
		height: fit-content;
		margin: 0 auto;
		overflow: hidden;
		padding-bottom: 200rpx;
	}

	/* 地址 */
	.addres {
		width: 690rpx;
		/* height: 230rpx; */
		border-bottom: 2rpx solid #F1F1F1;
		padding: 20rpx 0;
		margin-top: 20rpx;
	}

	.addresCont {
		width: 690rpx;
		/* height: 100rpx; */
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.addresIcon {
		width: 50rpx;
		height: 100rpx;
		display: block;
		margin-top: 10rpx;
	}

	.contIcon {
		width: 30rpx;
		height: 30rpx;
	}

	.contIcon2 {
		width: 15rpx;
		height: 30rpx;
	}

	.contInfoBox {
		width: 600rpx;
		height: 100rpx;
		line-height: 50rpx;
		font-weight: bold;
		font-size: 28rpx;
		color: #333333;
	}

	.infoTop {
		width: 600rpx;
		height: 50rpx;
	}

	.infoBom {
		width: 600rpx;
		height: 50rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		-o-text-overflow: ellipsis;
	}

	.but {
		width: 690rpx;
		height: 80rpx;
		background: #E84E22;
		border-radius: 50rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 32rpx;
		color: #FFFFFF;
		position: fixed;
		left: 30rpx;
		bottom: 100rpx;
	}
</style>